﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;

namespace MvcSiteMapProvider.Web
{
    /// <summary>
    /// XmlSiteMapController class
    /// </summary>
    public class XmlSiteMapController
        : Controller
    {
        /// <summary>
        /// GET: /XmlSiteMap/Index
        /// </summary>
        /// <returns>XmlSiteMapResult instance</returns>
        public ActionResult Index()
        {
            return new XmlSiteMapResult();
        }

        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routeCollection">The route collection.</param>
        public static void RegisterRoutes(RouteCollection routeCollection)
        {
            RouteBase xmlSiteMapRoute = new Route("sitemap.xml",
                                                  new RouteValueDictionary(
                                                      new { controller = "XmlSiteMap", action = "Index" }),
                                                  new MvcRouteHandler());

            if (routeCollection.Count == 0)
            {
                routeCollection.Add(xmlSiteMapRoute);
            }
            else
            {
                routeCollection.Insert(routeCollection.Count - 1, xmlSiteMapRoute);
            }
        }
    }
}
